package cn.gson.crm.model.pojos;

import org.hibernate.annotations.Cascade;

import javax.persistence.*;
import java.util.Objects;

@Entity
@Table(name = "user_role", schema = "CRM", catalog = "")
@IdClass(UserRolePK.class)
public class UserRole {
    private long yId;
    private long jId;
    private User userByYId;
    private Role roleByJId;

    @ManyToOne
    @JoinColumn(name="j_id",insertable=false,updatable=false)
    public Role getRoleByJId() {
        return roleByJId;
    }

    public void setRoleByJId(Role roleByJId) {
        this.roleByJId = roleByJId;
    }

    @Id
    @Column(name = "y_id")
    public long getyId() {
        return yId;
    }

    public void setyId(long yId) {
        this.yId = yId;
    }

    @Id
    @Column(name = "j_id")
    public long getjId() {
        return jId;
    }

    public void setjId(long jId) {
        this.jId = jId;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        UserRole userRole = (UserRole) o;
        return yId == userRole.yId &&
                jId == userRole.jId;
    }

    @Override
    public int hashCode() {
        return Objects.hash(yId, jId);
    }


}
